<template>
	<view class="bg-white">

		<view class="padding-xs flex align-center">

			<view class="flex-sub text-center">
				<view class="solid-bottom text-lg padding">
					<text class="text-black">宝宝喂养记录清单</text>
				</view>
				<view class="padding">
					<scroll-view scroll-x class="bg-white nav text-center">
						<view class="cu-item" :class="item.id==TabCur?'text-blue cur':''"
							v-for="(item,index) in babyList.data" :key="index" @tap="tabSelect" :data-id="item.id">
							{{item.babynike}}({{item.id}})
						</view>
					</scroll-view>
				</view>
			</view>
		</view>

		<view class="cu-timeline">
			<!-- <view class="cu-time">昨天</view>
			<view class="cu-item cur cuIcon-noticefill">
				<view class="content bg-green shadow-blur">
					<text>22:22</text> 【广州市】快件已到达地球
				</view>
			</view> -->

			<view class="cu-item text-cyan cuIcon-notice" v-if="list.code==200" v-for="item,index in list.data"
				:key=index @click="editLog(item.id)">
				<view class="bg-cyan content">
					<view class="item-self">
						<text>{{item.babynike}}</text>
						<text class="text-xxl">{{item.content}}ml/{{item.realitycontent}}ml</text>
						<text>{{item.create_time}}</text>
					</view>
				</view>
			</view>
			<view v-if="list.code==204" class="cu-item text-cyan cuIcon-notice">
				<view class="bg-cyan content">
					<view class="item-self">
						暂无数据
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import url_config from '@/common/config.js'
	export default {
		data() {
			return {
				list: [],
				TabCur: 0,
				scrollLeft: 0,
				babyList: [],
				uid: 0
			}
		},
		methods: {
			getMilkList(uid, bid = 0) {
				//获取喂养记录
				uni.request({
					url: url_config.api + 'getList/' + uid + '/' + bid,
					success: (res) => {
						//console.log(res)
						//if(res.data.code == 200){
						this.list = res.data
						//}
					}
				})
			},
			getBabyList(uid) {
				//获取宝宝
				uni.request({
					url: url_config.api + 'getBabyList/' + uid,
					success: (res) => {
						//console.log(res)
						if (res.data.code == 200) {
							this.babyList = res.data
						}
					}
				})
			},
			editLog(id) {
				//console.log(id)
				//跳转到编辑页面
				uni.redirectTo({
					url: '../edit/edit?id=' + id
				})
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.getMilkList(this.uid, this.TabCur);
			}
		},
		onShow() {
			const uid = uni.getStorageSync('user_id')
			this.uid = uid
			//console.log(uid)
			this.getMilkList(uid)
			this.getBabyList(uid)
		}
	}
</script>

<style>
	.item-self {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>
